package com.ruoyi.web.controller.business;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.HurtQuestionnaireScore;
import com.ruoyi.business.service.IHurtQuestionnaireScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患者疼痛量化得分
Controller
 *
 * @author ruoyi
 * @date 2024-04-20
 */
@RestController
@RequestMapping("/business/patientScore")
public class HurtQuestionnaireScoreController extends BaseController
{
    @Autowired
    private IHurtQuestionnaireScoreService hurtQuestionnaireScoreService;

    /**
     * 查询患者疼痛量化得分
列表
     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(HurtQuestionnaireScore hurtQuestionnaireScore)
    {
        startPage();
        List<HurtQuestionnaireScore> list = hurtQuestionnaireScoreService.selectHurtQuestionnaireScoreList(hurtQuestionnaireScore);
        return getDataTable(list);
    }

    /**
     * 导出患者疼痛量化得分
列表
     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:export')")
    @Log(title = "患者疼痛量化得分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HurtQuestionnaireScore hurtQuestionnaireScore)
    {
        List<HurtQuestionnaireScore> list = hurtQuestionnaireScoreService.selectHurtQuestionnaireScoreList(hurtQuestionnaireScore);
        ExcelUtil<HurtQuestionnaireScore> util = new ExcelUtil<HurtQuestionnaireScore>(HurtQuestionnaireScore.class);
        util.exportExcel(response, list, "患者疼痛量化得分数据");
    }

    /**
     * 获取患者疼痛量化得分
详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hurtQuestionnaireScoreService.selectHurtQuestionnaireScoreById(id));
    }

    /**
     * 新增患者疼痛量化得分

     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:add')")
    @Log(title = "患者疼痛量化得分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HurtQuestionnaireScore hurtQuestionnaireScore)
    {
        return toAjax(hurtQuestionnaireScoreService.insertHurtQuestionnaireScore(hurtQuestionnaireScore));
    }

    /**
     * 修改患者疼痛量化得分

     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:edit')")
    @Log(title = "患者疼痛量化得分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HurtQuestionnaireScore hurtQuestionnaireScore)
    {
        return toAjax(hurtQuestionnaireScoreService.updateHurtQuestionnaireScore(hurtQuestionnaireScore));
    }

    /**
     * 删除患者疼痛量化得分

     */
    @PreAuthorize("@ss.hasPermi('business:patientScore:remove')")
    @Log(title = "患者疼痛量化得分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hurtQuestionnaireScoreService.deleteHurtQuestionnaireScoreByIds(ids));
    }

    /**
     * 患者获取最近一次疼痛量化得分
     * @return
     */
    @GetMapping("/getPatientLastScore")
    public AjaxResult getPatientLastScore(){
        Long patientId = SecurityUtils.getUserId();
        Map<String, Object> map = hurtQuestionnaireScoreService.getPatientLastScore(patientId);
        if (map != null) {
            return AjaxResult.success(map);
        }else {
            return AjaxResult.success(new HashMap<>());
        }
    }

    /**
     * 医师获取患者疼痛量化结果
     * @return
     */
    @GetMapping("/getPatientScoreList")
    public AjaxResult getPatientScoreList(@RequestParam Long patientId){
        List<Map<String, Object>> list = hurtQuestionnaireScoreService.getPatientScoreList(patientId);
        return AjaxResult.success(list);
    }

    /**
     * 医师获取患者疼痛量化结果详情
     * @return
     */
    @GetMapping("/getPatientScoreDetail")
    public AjaxResult getPatientScoreDetail(@RequestParam Long id){
        Map<String, Object> map = hurtQuestionnaireScoreService.getPatientScoreDetail(id);
        if (map != null) {
            return AjaxResult.success(map);
        }
        else {
            return AjaxResult.success(new HashMap<>());
        }
    }

    /**
     * 获取问卷得分折线图
     * @return
     */
    @GetMapping("/getPatientAllScoreList")
    public AjaxResult getPatientAllScoreList(){
        Long patientId = SecurityUtils.getUserId();
        List<Map<String, Object>> odiList = hurtQuestionnaireScoreService.getODIList(patientId);
        List<Map<String, Object>> vasList = hurtQuestionnaireScoreService.getVASList(patientId);
        List<Map<String, Object>> pcsList = hurtQuestionnaireScoreService.getPCSList(patientId);
        List<Map<String, Object>> mcsList = hurtQuestionnaireScoreService.getMCSList(patientId);
        List<Map<String, Object>> standardList = hurtQuestionnaireScoreService.getStandardList(patientId);

        Map<String,Object>odiMap=new HashMap<>();
        odiMap.put("odiList",odiList);
        Map<String,Object>vasMap=new HashMap<>();
        vasMap.put("vasList",vasList);
        Map<String,Object>pcsMap=new HashMap<>();
        pcsMap.put("pcsMap",pcsList);
        Map<String,Object>mcsMap=new HashMap<>();
        mcsMap.put("mcsList",mcsList);
        Map<String,Object>standardMap=new HashMap<>();
        standardMap.put("standardMap",standardList);

        List<Map<String,Object>> allList=new ArrayList<>();
        allList.add(odiMap);
        allList.add(vasMap);
        allList.add(pcsMap);
        allList.add(mcsMap);
        allList.add(standardMap);

        return AjaxResult.success(allList);
    }

    /**
     * 医师获取患者最近一次疼痛量化得分
     * @return
     */
    @GetMapping("/getLastScoreByPatientId")
    public AjaxResult getLastScoreByPatientId(Long patientId){
        Map<String, Object> map = hurtQuestionnaireScoreService.getPatientLastScore(patientId);
        if(map != null){
            return AjaxResult.success(map);
        }else {
            return AjaxResult.success(new HashMap<>());
        }
    }

    /**
     * 医师获取患者问卷得分折线图
     * @return
     */
    @GetMapping("/getAllScoreListByPatientId")
    public AjaxResult getAllScoreListByPatientId(Long patientId){
        List<Map<String, Object>> odiList = hurtQuestionnaireScoreService.getODIList(patientId);
        List<Map<String, Object>> vasList = hurtQuestionnaireScoreService.getVASList(patientId);
        List<Map<String, Object>> pcsList = hurtQuestionnaireScoreService.getPCSList(patientId);
        List<Map<String, Object>> mcsList = hurtQuestionnaireScoreService.getMCSList(patientId);
        List<Map<String, Object>> standardList = hurtQuestionnaireScoreService.getStandardList(patientId);

        Map<String,Object>odiMap=new HashMap<>();
        odiMap.put("odiList",odiList);
        Map<String,Object>vasMap=new HashMap<>();
        vasMap.put("vasList",vasList);
        Map<String,Object>pcsMap=new HashMap<>();
        pcsMap.put("pcsMap",pcsList);
        Map<String,Object>mcsMap=new HashMap<>();
        mcsMap.put("mcsList",mcsList);
        Map<String,Object>standardMap=new HashMap<>();
        standardMap.put("standardMap",standardList);

        List<Map<String,Object>> allList=new ArrayList<>();
        allList.add(odiMap);
        allList.add(vasMap);
        allList.add(pcsMap);
        allList.add(mcsMap);
        allList.add(standardMap);

        return AjaxResult.success(allList);
    }

    /**
     * 获取患者odi和vas得分
     * @param patientId
     * @return
     */
    @GetMapping("/getPatientOdiAndVasList")
    public AjaxResult getPatientOdiAndVasList(Long patientId)
    {
        List<Map<String, Object>> odiList = hurtQuestionnaireScoreService.getOdiList(patientId);
        List<Map<String, Object>> vasList = hurtQuestionnaireScoreService.getVasList(patientId);

        Map<String,Object> map=new HashMap<>();
        map.put("odiList",odiList);
        map.put("vasList",vasList);

        return AjaxResult.success(map);
    }
}
